﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace FFmpegVideoClip.Lib.UtilityControlsTools
{
    //parameter 类型 int 0=标准处理的输入设置  1=后处理的输入设置 参数是项的索引
    [ValueConversion(typeof(string), typeof(int))]
    public class IntToStringConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!int.TryParse(value.ToString(), out int v) || !int.TryParse(parameter.ToString(), out int args))
                return 0;
            return args == 0 ? (v < 0 ? 0 : v + 1) : (v == -1 ? 0 : v == -2 ? 1 : v + 2);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is not int v || !int.TryParse(parameter.ToString(), out int args))
                return -1;
            //标准流处理
            return args == 0 ? (v <= 0 ? "-1" : (v - 1).ToString()) : (v <= 0 ? "-1" : v == 1 ? "-2" : (v - 2).ToString());
        }
    }
}
